package architect;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

/**
 * @title: CompletableFutureSample
 * @description:
 * @author: guan.xin
 * @create: 2021-09-25 09:38
 * @since: JDK8
 */
public class CompletableFutureSample {

    public static void main(String[] args) {
        try {
            supplyAsync();
        } catch (ExecutionException | InterruptedException e) {
            e.printStackTrace();
        }
    }

    private static Integer supplyAsync() throws ExecutionException, InterruptedException {
        CompletableFuture<Integer> future = CompletableFuture.supplyAsync(() -> {
            int i = 1 / 0;
            return 100;
        });
        return future.join();
        //return future.get();
    }

    public static CompletableFuture<Integer> compute() {
        final CompletableFuture<Integer> future = new CompletableFuture<>();
        return future;
    }
}
